package com.sgb.kjwl.repository.impl;

import com.sgb.kjwl.model.api.ApiSource;
import com.sgb.kjwl.model.entity.PickDeviceEntity2;
import com.sgb.kjwl.model.entity.PickLabourEntity;
import com.sgb.kjwl.model.entity.PickPackersEntity;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.kjwl.model.entity.pick.TenderDetailEntity3;
import com.sgb.kjwl.model.entity.pick.TenderDictEntity3;
import com.sgb.kjwl.model.entity.pick.TenderInfoBasicEntity3;
import com.sgb.kjwl.model.entity.supplier3.DictEntity3;
import com.swgk.core.base.model.entity.ListResponse;
import com.sgb.kjwl.repository.PickRepertory;
import com.swgk.core.base.api.BaseApiSource;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.base.model.preference.BasePreferenceSource;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.Observable;
import okhttp3.MediaType;
import okhttp3.RequestBody;

public class PickRepertoryImpl extends BaseRepertoryImpl implements PickRepertory {

    private ApiSource apiSource;

    public PickRepertoryImpl(BaseApiSource apiSource, BasePreferenceSource preferenceSource) {
        super(apiSource, preferenceSource);
        this.apiSource = (ApiSource) apiSource;
    }

    @Override
    public Observable<BaseEntity<ListResponse<List<PickDeviceEntity2>>>> getPickDeviceList(int page, int size, String areacode, List<String> cityList) {
        return apiSource.getPickDeviceList(page, size, areacode, cityList).compose(rxSchedulerHelper());
    }

    @Override
    public Observable<BaseEntity<ListResponse<List<PickLabourEntity>>>> getPickLaborList(int page, int size, String areacode, List<String> cityList) {
        return apiSource.getPickLaborList(page, size, areacode, cityList).compose(rxSchedulerHelper());
    }

    @Override
    public Observable<BaseEntity<List<String>>> uploadMutiFile(List<File> fileList) {
        Map<String, RequestBody> photos = new HashMap<>();
        int i = 0;
        for (File file : fileList) {
            RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
            photos.put("file" + "\"; filename=\"" + i + "image.jpg\"", requestBody);
            i++;
        }
        return apiSource.uploadMutiFile(photos).compose(rxSchedulerHelper());
    }

    @Override
    public Observable<BaseEntity<ListResponse<List<PickPackersEntity>>>> getPickPackersList(int page, int size, String areacode, List<String> cityList, List<String> typeList, String type) {
        return apiSource.getPickPackersList(page, size, areacode, cityList, typeList, type).compose(rxSchedulerHelper());
    }

    @Override
    public Observable<BaseEntity<List<PickSelectEntity>>> getPickPackersType() {
        return apiSource.getPickPackersType().compose(rxSchedulerHelper());
    }

    @Override
    public Observable<BaseEntity<TenderDetailEntity3<TenderInfoBasicEntity3<TenderDictEntity3>>>> getPickBidDetail(String id) {
        return apiSource.getPickBidDetail(id).compose(rxSchedulerHelper());
    }

    @Override
    public Observable<BaseEntity<List<DictEntity3>>> getPickRequireType() {
        return apiSource.getPickRequireType().compose(rxSchedulerHelper());
    }

    @Override
    public Observable<BaseEntity<List<DictEntity3>>> getPickEngineeringType() {
        return apiSource.getPickEngineeringType().compose(rxSchedulerHelper());
    }

    @Override
    public Observable<BaseEntity<List<DictEntity3>>> getPickScale(String type) {
        return apiSource.getPickScale(type).compose(rxSchedulerHelper());
    }

    @Override
    public Observable<BaseEntity<List<DictEntity3>>> getPickMaterialType() {
        return apiSource.getPickMaterialType().compose(rxSchedulerHelper());
    }
}
